﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiscreteEventModel.Common {

    public interface IFinalizer<T> where T : Finalizable {

        bool CanFinalize(T finalizable);
        bool TryFinalize(T finalizable);
    }

    public abstract class Finalizer<T> : IFinalizer<Finalizable>
        where T : Finalizable {

        protected abstract bool TryFinalize(T finalizable);
        
        public virtual bool CanFinalize(Finalizable finalizable) {
            return finalizable is T;
        }

        bool IFinalizer<Finalizable>.TryFinalize(Finalizable finalizable) {
            return this.TryFinalize(finalizable as T);
        }
    }
}
